﻿//----------------------------------------------------------------------------------------------------
// IAction is the base class for actions that the player can/will/has performed.
//----------------------------------------------------------------------------------------------------
package HG.Actions
{
	import HG.Debug;
	import HG.GameService;
	import HG.Managers.LevelManager;
	import HG.Managers.ActionManager;
	import HG.Visual.VisualNode;
	import HG.Managers.PlayerManager;
	
	public class ActionHack extends IAction
	{
		//----------------------------------------------------------------------------------------------------
		public function ActionHack(playerID:Number, nodeID:Number, type:Number)
		{
			super(playerID, nodeID, type);
			
			var levelManager:LevelManager = GameService.GetInstance().GetLevelManager();
			var visNode:VisualNode = levelManager.GetVisualNode(m_nodeID);
			
			// Get encryption mutliplier.
			if (visNode.GetEncryptionKey() != 0)
			{
				m_timeToComplete = 4;
			}
		}
		
		//----------------------------------------------------------------------------------------------------
		public override function Execute():Boolean
		{
			var levelManager:LevelManager = GameService.GetInstance().GetLevelManager();
			var playerManager:PlayerManager = GameService.GetInstance().GetPlayerManager();
			var visNode:VisualNode = levelManager.GetVisualNode(m_nodeID);
			
			m_executeCount++;
			
			var percentile:Number = (100 / m_timeToComplete) * m_executeCount;
			Debug.ASSERT(percentile, "Bad Progress value");
			
			visNode.SetProgressDisplay(percentile, (GetOwner() == playerManager.GetCurrentPlayerID()));
			
			if (m_executeCount >= m_timeToComplete)
			{
				visNode.AddOcupant(m_playerID);
				visNode.ClearPendingAction();
			
				levelManager.RaiseNodeCapturedEvent(visNode, m_playerID);
			}

			return true;
		}
		
		//----------------------------------------------------------------------------------------------------
	}
}